﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Maticsoft.Common;
public partial class PromotionAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            com.BLL.laibendi.T_Seller bll = new com.BLL.laibendi.T_Seller();
            DataSet ds = bll.GetSellerNameList("");

            this.DropDownList1.DataTextField = "SellerName";
            this.DropDownList1.DataValueField = "SellerId";

            this.DropDownList1.DataSource = ds;
            this.DropDownList1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string strErr = "";

        if (!PageValidate.IsNumber(txtPromotionCatId.Text))
        {
            strErr += "请选择促销类别错误！\\n";
        }
        if (this.txtPromotionTitle.Text.Trim().Length == 0)
        {
            strErr += "PromotionTitle不能为空！\\n";
        }
        if (this.txtPromotionContent.Text.Trim().Length == 0)
        {
            strErr += "PromotionContent不能为空！\\n";
        }
        if (!PageValidate.IsDateTime(txtActiveFromTime.Text))
        {
            strErr += "ActiveFromTime格式错误！\\n";
        }
        if (!PageValidate.IsDateTime(txtActiveToTime.Text))
        {
            strErr += "ActiveToTime格式错误！\\n";
        }
     

        if (strErr != "")
        {
            MessageBox.Show(this, strErr);
            return;
        }

        long SellerId = long.Parse(this.DropDownList1.SelectedValue);
        int PromotionCatId = int.Parse(this.txtPromotionCatId.Text);
        string PromotionTitle = this.txtPromotionTitle.Text;
        string PromotionContent = this.txtPromotionContent.Text;
        DateTime ActiveFromTime = DateTime.Parse(this.txtActiveFromTime.Text);
        DateTime ActiveToTime = DateTime.Parse(this.txtActiveToTime.Text);
      

        com.Model.laibendi.T_Promotion model = new com.Model.laibendi.T_Promotion();
        model.SellerId = SellerId;
        model.PromotionCatId = PromotionCatId;
        model.PromotionTitle = PromotionTitle;
        model.PromotionContent = PromotionContent;
        model.ActiveFromTime = ActiveFromTime;
        model.ActiveToTime = ActiveToTime;
        model.Remark = "";
        model.CreateTime = System.DateTime.Now;
        model.ModifyTime = System.DateTime.Now;
        model.hits = 0;

        com.BLL.laibendi.T_Promotion bll = new com.BLL.laibendi.T_Promotion();
        bll.Add(model);
        Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", ".");
    }
}
